<template>
  <div class="app-container">
    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-search"
          size="mini"
          @click="handleSearch"
          >搜索
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-edit"
          size="mini"
          :disabled="single"
          @click="handleCheck"
          v-hasPermi="['device:preservePlan:edit']"
          >审核
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-delete"
          size="mini"
          :disabled="single"
          @click="openRevoke = true"
          v-hasPermi="['device:preservePlan:edit']"
          >撤回
        </el-button>
      </el-col>

      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          :loading="exportLoading"
          @click="handleExport"
          v-hasPermi="['device:preservePlan:export']"
          >导出
        </el-button>
      </el-col>
      <Tag type="dot" size="default" color="#0fac09">提交</Tag>
      <Tag type="dot" size="default" color="#0323af">审核</Tag>
      <Tag type="dot" size="default" color="#bb0331">结案</Tag>

      <!-- 分页效果 -->
      <el-col :span="2.2" style="position: absolute; right: 0px; top: 0">
        <Page
          style="margin-right: 0px"
          :current="queryParams.pageNum"
          :page-size="queryParams.pageSize"
          :total="total"
          @on-change="pageChange"
          simple
        ></Page>
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      highlight-current-row
      border
      stripe
      v-loading="loading"
      id="preservePlanCheck"
      :height="tableH"
      :data="preservePlanList"
      :cell-style="iCellStyle"
      @selection-change="handleSelectionChange"
      :header-cell-style="{ 'text-align': 'center' }"
    >
      <el-table-column
        label="#"
        type="index"
        fixed="left"
        width="40"
        align="center"
      />
      <el-table-column
        type="selection"
        fixed="left"
        width="55"
        align="center"
      />
      <el-table-column
        label="计划单号"
        :show-overflow-tooltip="true"
        width="135"
        prop="bplDjbh"
      />
      <el-table-column
        label="设备编号"
        :show-overflow-tooltip="true"
        width="180"
        prop="bplSbdm"
      />
      <el-table-column
        label="设备名称"
        :show-overflow-tooltip="true"
        width="135"
        align="center"
        prop="bplName"
      />
      <el-table-column
        label="使用部门"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplSybm"
      >
        <template v-slot="scope">
          <dict-tag :options="deptList" :value="scope.row.bplSybm" />
        </template>
      </el-table-column>
      <el-table-column
        label="保养周期"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplByzqms"
      />
      <el-table-column
        label="计划保养时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="bplJhbysj"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.bplJhbysj, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="实际完成时间"
        :show-overflow-tooltip="true"
        align="center"
        prop="bplSjwcsj"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.bplSjwcsj, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="用时"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplHour"
      />
      <el-table-column
        label="备注"
        :show-overflow-tooltip="true"
        width="120"
        prop="bplDesc"
      />
      <el-table-column
        label="是否提交"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplTjflag"
      >
        <template v-slot="scope">
          <span v-if="scope.row.bplTjflag == 1">已提交</span>
          <span v-if="scope.row.bplTjflag == 0">未提交</span>
        </template>
      </el-table-column>
      <el-table-column
        label="撤回原因"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplNgdesc"
      />
      <el-table-column
        label="单据状态"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplZtbz"
      >
        <template #default="scope">
          <dict-tag :options="bplZtbzOptions" :value="scope.row.bplZtbz" />
        </template>
      </el-table-column>
      <el-table-column
        label="建立人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplJlry"
      />
      <el-table-column
        label="建立日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="bplJlrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.bplJlrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="审核人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplShry"
      />
      <el-table-column
        label="审核日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="bplShrq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.bplShrq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="结案人员"
        :show-overflow-tooltip="true"
        width="100"
        align="center"
        prop="bplJary"
      />
      <el-table-column
        label="结案日期"
        :show-overflow-tooltip="true"
        align="center"
        prop="bplJarq"
        width="150"
      >
        <template #default="scope">
          <span>{{
            parseTime(scope.row.bplJarq, "{y}-{m}-{d} {h}:{i}:{s}")
          }}</span>
        </template>
      </el-table-column>
      <el-table-column
        label="操作"
        align="center"
        width="100"
        fixed="right"
        class-name="small-padding fixed-width"
      >
        <template #default="scope">
          <el-button
            size="mini"
            type="text"
            @click="recordClick(scope.row)"
            :disabled="scope.row.bplZtbz !== 4 || scope.row.bylDjbh == null"
            >保养记录
          </el-button>
        </template>
      </el-table-column>
    </el-table>

    <!-- 查询对话框   -->
    <el-dialog
      :title="title"
      v-model="openSearch"
      :close-on-click-modal="false"
      draggable
      width="400px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="24">
          <el-form-item label="计划单号" prop="bplDjbh">
            <el-input
              v-model="queryParams.bplDjbh"
              placeholder="请输入计划单号"
              clearable
              style="width: 240px"
              size="small"
              @keyup.enter.native="handleQuery"
            />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="建立日期">
            <el-date-picker
              v-model="daterangeBplJlrq"
              size="small"
              style="width: 240px"
              value-format="yyyy-MM-dd"
              type="daterange"
              range-separator="-"
              start-placeholder="开始日期"
              end-placeholder="结束日期"
            ></el-date-picker>
          </el-form-item>
        </el-col>
        <el-form-item label="单据状态">
          <el-radio-group v-model="queryParams.bplZtbz">
            <el-radio
              v-for="dict in ZtbzOptions"
              :key="dict.dictValue"
              :label="dict.dictValue"
              >{{ dict.dictLabel }}
            </el-radio>
          </el-radio-group>
        </el-form-item>
        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancel">取消</el-button>
            <el-button type="primary" @click="handleQuery">确认</el-button>
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 从列表中选择所选部门 -->
    <el-dialog
      :title="title"
      v-model="openDevice"
      :close-on-click-modal="false"
      draggable
      width="500px"
      append-to-body
    >
      <el-form
        :model="queryParams"
        ref="queryForm"
        :inline="true"
        v-show="showSearch"
        label-width="68px"
      >
        <el-col :span="24">
          <el-form-item label="筛选条件" prop="params.find">
            <el-input
              v-model="queryParams.params.find"
              clearable
              size="small"
              @input="clickAddButton"
            />
          </el-form-item>
        </el-col>

        <el-table
          highlight-current-row
          border
          stripe
          v-loading="loading"
          height="500"
          :data="deviceList"
          @row-click="handleDevice"
          :header-cell-style="{ 'text-align': 'center' }"
        >
          <el-table-column label="#" type="index" width="40" align="center" />
          <el-table-column
            label="设备代码"
            width="135"
            prop="bplSbdm"
            align="center"
          />
          <el-table-column
            label="设备名称"
            :show-overflow-tooltip="true"
            width="135"
            align="center"
            prop="bplName"
          />
          <el-table-column
            label="设备类型"
            :show-overflow-tooltip="true"
            width="100"
            align="center"
            prop="bplType"
          >
            <template v-slot="scope">
              <dict-tag :options="deviceTypeList" :value="scope.row.bplType" />
            </template>
          </el-table-column>
        </el-table>

        <el-col :span="24">
          <el-form-item
            style="margin-top: 25px; display: flex; justify-content: flex-end"
          >
            <el-button @click="cancelDevice">取消</el-button>
            <el-button type="primary" @click="openDevice = false"
              >确认</el-button
            >
          </el-form-item>
        </el-col>
      </el-form>
    </el-dialog>

    <!-- 撤回原因弹出框 -->
    <el-dialog
      title="确认"
      v-model="openRevoke"
      :close-on-click-modal="false"
      draggable
      width="500px"
      append-to-body
    >
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-col :span="24">
          <el-form-item label="撤回理由" prop="bplNgdesc">
            <el-input
              type="input"
              placeholder="撤回理由"
              v-model="form.bplNgdesc"
            >
            </el-input>
          </el-form-item>
        </el-col>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="handleRevoke">确 定</el-button>
      </div>
    </el-dialog>

    <!-- 修改设备保养作业对话框 -->
    <el-dialog
      :class="$style.tabSbby"
      :title="title"
      v-model="openFix"
      :close-on-click-modal="false"
      draggable
      width="830px"
      append-to-body
    >
      <el-form
        :model="formFix"
        :rules="rules"
        ref="formSbby"
        style="display: flex; flex-wrap: wrap"
        label-width="80px"
      >
        <el-form-item label="保养单号" prop="bymDjbh">
          <el-input
            disabled
            v-model="formFix.bymDjbh"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="保养类别" prop="bymBylb">
          <el-select
            v-model="formFix.bymBylb"
            disabled
            size="mini"
            style="width: 180px"
            filterable
            placeholder="请选择保养类型"
          >
            <el-option
              v-for="dict in upKeepList"
              :key="dict.dictValue"
              :label="'[' + dict.dictValue + ']' + dict.dictLabel"
              :value="dict.dictValue"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item label="计划单号" prop="bymBpdh">
          <el-input
            disabled
            v-model="formFix.bymBpdh"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="产品型号" prop="bymCpxh">
          <el-input
            disabled
            v-model="formFix.bymCpxh"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="工装编号" prop="bymGzbh">
          <el-input
            disabled
            v-model="formFix.bymGzbh"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="使用设备" prop="bymSysb">
          <el-input
            disabled
            v-model="formFix.bymSysb"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="模具编号" prop="bymMjbh">
          <el-input
            disabled
            v-model="formFix.bymMjbh"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="模具名称" prop="mjmMjmc">
          <el-input
            disabled
            v-model="formFix.mjmMjmc"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="模具尺寸" prop="mjmMjgg">
          <el-input
            disabled
            v-model="formFix.mjmMjgg"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="制作时间" prop="mjmDcrq">
          <el-input
            disabled
            v-model="formFix.mjmDcrq"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>

        <el-form-item label="腔型数量" prop="mjmXsms">
          <el-input
            disabled
            v-model="formFix.mjmXsms"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>
        <el-form-item label="样件描述" prop="bymYjms">
          <el-input
            disabled
            v-model="formFix.bymYjms"
            style="width: 180px"
            size="mini"
          />
        </el-form-item>
      </el-form>
      <el-tabs v-model="activeName">
        <el-tab-pane label="保全工作" name="first">
          <hd-table
            :columns="[
              { title: '#', type: 'index', width: '40' },
              { title: '保全类', key: 'bnlNrlb', width: '100' },
              { title: '保全项目', key: 'bnlNrms', width: '348' },
              { title: '保养内容', key: 'bydBynr', width: '100' },
              { title: '保全人员', key: 'bydZrry', width: '100' },
              { title: '备件情况', key: 'bydDesc', width: '100' },
            ]"
            v-model="maintenanceWorkList"
            :readOnly="true"
          >
            <template #bydBynr="scope">
              <el-input disabled v-model="scope.row.bydBynr" />
            </template>
            <template #bydZrry="scope">
              <el-input disabled v-model="scope.row.bydZrry" />
            </template>
            <template #bydDesc="scope">
              <el-input disabled v-model="scope.row.bydDesc" />
            </template>
          </hd-table>
        </el-tab-pane>
        <el-tab-pane label="恢复精度工作" name="second">
          <hd-table
            :columns="sys_m_child_3"
            v-model="recoveryAccuracyList"
            :readOnly="true"
          />
        </el-tab-pane>
        <el-tab-pane label="其他保全检查项目" name="third">
          <hd-table
            :columns="[
              { title: '#', type: 'index', width: '40' },
              { title: '检查项目', key: 'bydJcxmms' },
              {
                title: '是否检查',
                key: 'bydChkjg',
                width: '120',
                align: 'center',
              },
            ]"
            v-model="otherProjectsList"
            :readOnly="true"
          >
            <template #bydChkjg="scope"
              ><el-checkbox disabled v-model="scope.row.bydChkjg"
            /></template>
          </hd-table>
        </el-tab-pane>
      </el-tabs>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="openFix = false">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
import {
  addPreservePlan,
  checkPreservePlanRevoke,
  checkPreservePlanSuccess,
  delPreservePlan,
  exportPreservePlan,
  getPreservePlan,
  listDeviceAll,
  listPreservePlan,
  preservePlanSubmit,
  updatePreservePlan,
} from "@/api/device/preservePlan";
import { listDept, listEfficientDept } from "@/api/system/dept";
import { getEffectiveDeviceType } from "@/api/device/deviceType";
import HdTable from "@/components/HdTable";
import {
  listPreserveContext,
  listPreserveInfo,
} from "@/api/device/preserveWork";

export default {
  name: "PreservePlanCheck",
  components: { HdTable },
  data() {
    return {
      // 遮罩层
      loading: true,
      // 导出遮罩层
      exportLoading: false,
      tableH: document.body.clientHeight - 290,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      openSearch: false,
      // 默认选择第一个表
      activeName: "first",
      // 总条数
      total: 0,
      // 设备保养计划-申请计划表格数据
      preservePlanList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      openDevice: false,
      openRevoke: false,
      openFix: false,
      // 单据状态字典
      bplZtbzOptions: [],
      // 三表所有的设备
      deviceList: [],
      // 设备类型
      deviceTypeList: [],
      // 有效的设备类型
      deviceEfficientTypeList: [],
      // 保全工作
      maintenanceWorkList: [],
      // 恢复精度工作
      recoveryAccuracyList: [],
      // 其他保全项目检查
      otherProjectsList: [],
      // 保养类别
      upKeepList: [],
      // 全部部门
      deptList: [],
      // 有效的部门
      deptEfficientList: [],
      // 建立日期时间范围
      daterangeBplJlrq: [
        new Date(new Date().getTime() - 1000 * 60 * 60 * 24 * 30 * 3),
        new Date(new Date().getTime() + 1000 * 60 * 60 * 24),
      ],
      ZtbzOptions: [
        {
          dictLabel: "未审核",
          dictValue: "1",
        },
        {
          dictLabel: "已审核",
          dictValue: "2",
        },
        {
          dictLabel: "全部",
          dictValue: "",
        },
      ],
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: document.body.clientHeight > 900 ? 25 : 17,
        bplTjflag: 1,
        bplDjbh: null,
        bplZtbz: "1",
        bplJlrq: null,
        params: null,
      },
      // 提交参数
      flagOptions: [],
      // 表单参数
      form: {},
      formFix: {},
      // 表单校验
      rules: {
        bplSbdm: [
          { required: true, message: "设备编号为必填", trigger: "blur" },
        ],
        bplName: [
          { required: true, message: "设备名称为必填", trigger: "blur" },
        ],
        bplSybm: [
          { required: true, message: "使用部门为必选", trigger: "blur" },
        ],
      },
      sys_m_child_3: [
        {
          title: "#",
          type: "index",
          width: 40,
          align: "center",
          fixed: "left",
        },
        {
          type: "selection",
          width: 40,
        },
        {
          title: "设备问题",
          key: "bydWtms",
          minWidth: 120,
          sortable: true,
        },
        {
          title: "分析产生原因",
          key: "bydYyms",
          minWidth: 150,
          sortable: true,
        },
        {
          title: "解决措施",
          key: "bydGsms",
          sortable: true,
        },
        {
          title: "维修人员",
          key: "bydZrry",
          minWidth: 120,
          sortable: true,
        },
        {
          title: "备件情况",
          key: "bydDesc",
          width: 120,
          sortable: true,
        },
      ],
    };
  },
  created() {
    // 获取全部设备类型
    getEffectiveDeviceType().then((res) => {
      this.deviceTypeList = res.data;
      for (let item of this.deviceTypeList) {
        item.dictLabel = item.dtypeName;
        item.listClass = "default";
        item.dictValue = item.dtypeCode;
      }
    });
    // 获取有效设备类型
    getEffectiveDeviceType("0").then((res) => {
      this.deviceEfficientTypeList = res.data;
      for (let item of this.deviceEfficientTypeList) {
        item.dictLabel = item.dtypeName;
        item.listClass = "default";
        item.dictValue = item.dtypeCode;
      }
    });
    // 获取全部部门
    listDept().then((res) => {
      this.deptList = res.data;
      for (let item of this.deptList) {
        item.dictLabel = item.deptName;
        item.listClass = "default";
        item.dictValue = item.deptId + "";
      }
    });
    // 获取有效部门
    listEfficientDept("0").then((res) => {
      this.deptEfficientList = res.data;
      for (let item of this.deptEfficientList) {
        item.dictLabel = item.deptName;
        item.listClass = "default";
        item.dictValue = item.deptId + "";
      }
    });
    this.getDicts("device_preserve_plan").then((response) => {
      this.bplZtbzOptions = response.data;
    });
    this.getAllDicts("device_upkeep_style").then((response) => {
      this.upKeepList = response.data;
    });
    this.getList();
  },
  methods: {
    /** 查询设备保养计划-申请计划列表 */
    getList() {
      this.loading = true;
      this.queryParams.params = {};
      if (null != this.daterangeBplJlrq && "" != this.daterangeBplJlrq) {
        this.queryParams.params["beginBplJlrq"] = this.moment(
          this.daterangeBplJlrq[0]
        ).format("YYYY-MM-DD");
        this.queryParams.params["endBplJlrq"] = this.moment(
          this.daterangeBplJlrq[1]
        ).format("YYYY-MM-DD");
      }
      listPreservePlan(this.queryParams).then((response) => {
        this.preservePlanList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },

    //load
    load() {
      if (
        this.queryParams.pageNum <
        Math.ceil(this.total / this.queryParams.pageSize)
      ) {
        this.queryParams.pageSize = 25;
        this.queryParams.pageNum++;
      }
      return 0;
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.openSearch = false;
      this.reset();
    },
    // 所有设备窗口取消按钮
    cancelDevice() {
      this.form.bplSbdm = "";
      this.form.bplName = "";
      this.openDevice = false;
    },
    /** 表格点击事件 */
    handleDevice(row) {
      this.form.bplSbdm = row.bplSbdm;
      this.form.bplName = row.bplName;
    },
    // 表单重置
    reset() {
      this.form = {
        bplId: null,
        bplDjbh: null,
        bplSbdm: null,
        bplType: null,
        bplName: null,
        bplSybm: null,
        bplByzqms: null,
        bplJhbysj: null,
        bplSjwcsj: null,
        bplHour: null,
        bplDesc: null,
        bplTjflag: null,
        bplNgdesc: null,
        bplZtbz: null,
        bplJlry: null,
        bplJlrq: null,
        bplShry: null,
        bplShrq: null,
        bplJary: null,
        bplJarq: null,
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.preservePlanList = [];
      this.getList();
      this.openSearch = false;
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.daterangeBplJlrq = [];
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.bplId);
      this.single = selection.length !== 1 || this.isCheck(selection);
      this.multiple = !selection.length || this.isSubmit(selection);
    },
    isSubmit(selection) {
      for (let i of selection) {
        if (i.bplZtbz != 1 || i.bplTjflag != 0) return true;
      }
      return false;
    },
    isCheck(selection) {
      for (let i of selection) {
        if (i.bplZtbz != 1) return true;
      }
      return false;
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "添加设备保养计划-申请计划";
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const bplIds = row.bplId || this.ids;
      getPreservePlan(bplIds).then((response) => {
        this.form = response.data;
        this.open = true;
        this.title = "修改设备保养计划-申请计划";
      });
    },
    handleSubmit(row) {
      this.reset();
      const bplIds = row.bplId || this.ids;
      preservePlanSubmit(bplIds)
        .then((res) => {
          this.msgSuccess("提交成功");
          this.getList();
        })
        .catch(() => {
          this.msgError("提交失败");
          this.getList();
        });
    },
    /** 审核通过 */
    handleCheck() {
      const bplIds = this.ids;
      checkPreservePlanSuccess(bplIds).then((res) => {
        this.msgSuccess("审核通过");
        this.getList();
      });
    },
    /** 审核不通过，添加不通过原因 */
    handleRevoke(row) {
      this.form.bplId = this.ids[0];

      checkPreservePlanRevoke(this.form).then((res) => {
        this.msgSuccess("撤回成功");
        this.openRevoke = false;
        this.getList();
      });
    },
    /** 保养记录点击事件 */
    recordClick(row) {
      const id = row.bylDjbh;
      listPreserveInfo(id).then((res) => {
        this.formFix = res.data;
      });
      listPreserveContext(id, "1").then((res) => {
        this.maintenanceWorkList = res.data;
      });
      listPreserveContext(id, "2").then((res) => {
        this.recoveryAccuracyList = res.data;
      });
      listPreserveContext(id, "3").then((res) => {
        this.otherProjectsList = res.data;
      });
      this.openFix = true;
    },
    handleSearch() {
      this.reset();
      this.title = "查询设备保养计划-申请计划";
      this.openSearch = true;
    },
    /** 提交按钮 */
    submitForm() {
      this.$refs["form"].validate((valid) => {
        if (valid) {
          if (this.form.bplId != null) {
            updatePreservePlan(this.form).then((response) => {
              this.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addPreservePlan(this.form).then((response) => {
              this.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const bplIds = row.bplId || this.ids;
      this.$confirm(
        '是否确认删除设备保养计划-申请计划编号为"' + bplIds + '"的数据项?',
        "警告",
        {
          confirmButtonText: "确定",
          cancelButtonText: "取消",
          type: "warning",
        }
      )
        .then(function () {
          return delPreservePlan(bplIds);
        })
        .then(() => {
          this.getList();
          this.msgSuccess("删除成功");
        })
        .catch(() => {});
    },
    /** 导出按钮操作 */
    handleExport() {
      const queryParams = this.queryParams;
      this.$confirm("是否确认导出所有设备保养计划-申请计划数据项?", "警告", {
        confirmButtonText: "确定",
        cancelButtonText: "取消",
        type: "warning",
      })
        .then(() => {
          this.exportLoading = true;
          return exportPreservePlan(queryParams);
        })
        .then((response) => {
          this.download(response.msg);
          this.exportLoading = false;
        })
        .catch(() => {});
    },
    pageChange(page) {
      this.queryParams.pageNum = page;
      this.getList();
    },
    /** 添加界面点击加号事件 */
    clickAddButton() {
      this.openDevice = true;
      listDeviceAll(this.queryParams).then((res) => {
        this.deviceList = res.rows;
      });
    },
    /** 不同状态显示效果 */
    iCellStyle: function ({ row, column, rowIndex, columnIndex }) {
      // 已提交
      if (row.bplTjflag == 0 && row.bplZtbz == 1) {
        return "padding:0px 0";
      }
      // 已提交，未审核
      else if (row.bplTjflag == 1 && row.bplZtbz == 1) {
        return "padding:0px 0;color:rgb(15, 152, 86)";
      }
      // 已审核
      else if (row.bplTjflag == 1 && row.bplZtbz == 2) {
        return "padding:0px 0;color:rgb(0, 0, 255)";
      }
      // 已结案
      else if (row.bplZtbz == 4) {
        return "padding:0px 0;color:#bb0331";
      } else {
        return "padding:0px 0";
      }
    },
  },
};
</script>

<style module lang="scss">
.hdDivButton {
  button {
    width: calc(50% - 5px);
  }
}

.tabSbby {
  :global {
    .el-form-item {
      margin-bottom: 5px;
    }
    .el-table .cell {
      height: 28px;
      line-height: 28px;
    }
    .el-input--medium .el-input__inner {
      height: 28px;
      line-height: 28px;
      padding: 0px;
    }
  }
}
</style>
